import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/config/app_data_config.dart';
import 'package:app/src/http/bean/wroks/search_bean.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/http/bean/ywx_limit.dart';
import 'package:app/src/ui/popuwindow/popuwindow_search.dart';
import 'package:app/src/ui/route/works/public/review_list.dart';

import '../../../../manager/ywx_manager.dart';

///采购合同审核
class PurContractAuditRoute extends StatefulWidget {
  YwxItem item;

  PurContractAuditRoute(this.item);

  @override
  _State createState() => _State();
}

class _State extends State<PurContractAuditRoute> {
  _Presenter presenter = _Presenter();

  @override
  void initState() {
    super.initState();
    if (presenter.searchInfo == null) {
      presenter.searchInfo = SearchInfo(widget.item)
        ..isShowStatus = true //审核状态
        ..isShowStatusAll = false //审核状态不具备全显示
        ..isPurContractCode = true //采购合同号
        ..isPurBodyCode = true //子合同编号
        ..isShowOutCode = true //子合同外部编号
        ..isShowSupplier = true //供应商
        ..isCreater = true //采购员
        // ..isShowTypeOfMaterial=true//fixme 是否显示物料类型，新加的，需要根据权限去动态判断。
        ..isShowTypeOfMaterial = false
        ..isShowTypeOfMaterialWithHasLimit = true //根据权限去获取物料类型
        ..isShowAddTime = false; //申请日期
    }
    // print("待审核物料类型：${widget.item.ReviewType}");
    // print("待审核物料类型：${ReviewType.GetPurOrderMT02}");
    // print("待审核物料类型：${ReviewType.GetPurOrderMT03}");
    // print("${(widget.item.ReviewType == ReviewType.GetPurOrderMT02)}");
    // print("${(widget.item.ReviewType == ReviewType.GetPurOrderMT03)}");
    if (widget.item.ReviewType == ReviewType.GetPurContractMT02) {
      //辅料请购单审核
      presenter.searchInfo?.MaterialType = "MT02";
    } else if (widget.item.ReviewType == ReviewType.GetPurContractMT03) {
      //五金请购单审核
      presenter.searchInfo?.MaterialType = "MT03";
    } else {
      //原片请购单审核
      presenter.searchInfo?.MaterialType = "";
    }
    // print("搜索条件物料类型：${presenter.searchInfo?.MaterialType}");
  }

  @override
  Widget build(BuildContext context) {
    px.init(context);
    presenter.searchInfo?.ShowOutCodeName =
        AppStrings.of(context).ContractOutCode; //子合同外部编号
    var scaffold = AppUi.getScaffoldWithReView(
        context, _body(context), widget.item, presenter.searchInfo!, () {
      //print("===============================================================搜索刷新");
      presenter.setStateBody?.call(() {});
    });
    return WillPopScope(
      child: scaffold,
      onWillPop: () async {
        return true; //true 不屏蔽返回键
      },
    );
  }

  Widget _body(BuildContext context) {
    //print("===============================================================页面刷新:$isShowPopuMenuWithSearch");
    return StatefulBuilder(
        builder: (BuildContext context, StateSetter setState) {
      presenter.setStateBody = setState;
      List<Widget> children = [];
      //搜索条件
      var searchLayout =
          AppUi.getSearchLayout(context, presenter.searchInfo!, () {
        presenter.setStateBody?.call(() {});
      });
      children.add(searchLayout);
      //审核列表
      var reviewList = ReviewList(widget.item, presenter.searchInfo!, true);
      children.add(Expanded(child: reviewList));
      return Column(
        children: children,
      );
    });
  }
}

class _Presenter {
  ///搜索条件
  SearchInfo? searchInfo = null;

  ///body视图状态
  StateSetter? setStateBody;
}
